package day14;

public class homework0002 extends Thread {
    homework002 h02;

    public homework0002(homework002 h02) {
        this.h02 = h02;
    }

    @Override
    public void run() {
        synchronized (h02.getlock()) {
            while (h02.getCount()>0) {
                if (h02.isFlag()) {
                    for (int i = 0; i < 3; i++) {
                        System.out.println("这是子程序");
                        try {
                            sleep(100);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    h02.setFlag(false);
                    h02.getlock().notify();
                } else {
                    try {
                        h02.getlock().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
